//
//  CPDock.m
//  财富管家
//
//  Created by rimi on 15/9/25.
//  Copyright (c) 2015年 rimicp. All rights reserved.
//

#import "CPDock.h"
#import "CPTabItem.h"
#import "CPDockItem.h"

typedef NS_ENUM(NSUInteger, ButtonTag) {
    headTag = 100,
    slideTag,
    loginTag,

};
@interface CPDock()
{
    CPTabItem *_selectedItem; // 被选中的标签
   
}
@end


@implementation CPDock



- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // 1.自动伸缩(高度 + 右边间距)
        self.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleRightMargin;
    }
    return self;
}


- (void)addOneTab:(NSString *)icon selectedIcon:(NSString *)selectedIcon  index:(NSInteger)index
{
    CPTabItem *item = [[CPTabItem alloc] init];
    [item setIcon:icon selectedIcon:selectedIcon];
    item.frame = CGRectMake((index - 1)  * 120 , 0 , 0, 0);
    [item addTarget:self action:@selector(tabClick:) forControlEvents:UIControlEventTouchDown];
    item.tag = index - 1;
    [self addSubview:item];
    
    if (index == 1) {
        [self tabClick:item];
    }
}

#pragma mark 监听tab点击
- (void)tabClick:(CPTabItem *)tab
{
    // 0.通知代理
    if ([_delegate respondsToSelector:@selector(dock:tabChangeFrom:to:)]) {
        [_delegate dock:self tabChangeFrom:_selectedItem.tag to:tab.tag];
    }
    
    // 1.控制状态
    _selectedItem.enabled = YES;
    tab.enabled = NO;
    _selectedItem = tab;
}


#pragma mark 重写setFrame方法：内定自己的高度
- (void)setFrame:(CGRect)frame{

    frame.size.height = 40;
    [super setFrame:frame];
}







@end
